package com.research.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.enums.BusinessType;
import com.research.domain.entity.Regulation;
import com.research.service.IRegulationService;
import com.common.utils.poi.ExcelUtil;
import com.common.core.page.TableDataInfo;

/**
 * 研究机构-规章制度Controller
 *
 * @author hst
 * @date 2025-03-13
 */
@RestController
@RequestMapping("/research/regulation")
public class RegulationController extends BaseController
{
    @Autowired
    private IRegulationService regulationService;

    /**
     * 查询研究机构-规章制度列表
     */
    @PreAuthorize("@ss.hasPermi('research:regulation:list')")
    @GetMapping("/list")
    public TableDataInfo list(Regulation regulation)
    {
        startPage();
        List<Regulation> list = regulationService.selectRegulationList(regulation);
        return getDataTable(list);
    }

    /**
     * 导出研究机构-规章制度列表
     */
    @PreAuthorize("@ss.hasPermi('research:regulation:export')")
    @Log(title = "研究机构-规章制度", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Regulation regulation)
    {
        List<Regulation> list = regulationService.selectRegulationList(regulation);
        ExcelUtil<Regulation> util = new ExcelUtil<Regulation>(Regulation.class);
        util.exportExcel(response, list, "研究机构-规章制度数据");
    }

    /**
     * 获取研究机构-规章制度详细信息
     */
    @PreAuthorize("@ss.hasPermi('research:regulation:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(regulationService.selectRegulationByID(ID));
    }

    /**
     * 新增研究机构-规章制度
     */
    @PreAuthorize("@ss.hasPermi('research:regulation:add')")
    @Log(title = "研究机构-规章制度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Regulation regulation)
    {
        return toAjax(regulationService.insertRegulation(regulation));
    }

    /**
     * 修改研究机构-规章制度
     */
    @PreAuthorize("@ss.hasPermi('research:regulation:edit')")
    @Log(title = "研究机构-规章制度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Regulation regulation)
    {
        return toAjax(regulationService.updateRegulation(regulation));
    }

    /**
     * 删除研究机构-规章制度
     */
    @PreAuthorize("@ss.hasPermi('research:regulation:remove')")
    @Log(title = "研究机构-规章制度", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(regulationService.deleteRegulationByIDs(IDs));
    }
}
